package com.supermap.business.cloud.maker;

import com.alibaba.dubbo.config.annotation.Reference;
import com.supermap.dataservice.redis.JedisComponent;
import com.supermap.dataservice.util.JSONUtils;
import com.supermap.dubbo.api.cloud.maker.AdInfo;
import com.supermap.dubbo.api.cloud.maker.MakerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author aqua
 * @description
 * @date 2019年11月20 14:43
 * @email 1301584033@qq.com
 */
@Controller
@RequestMapping("/cloud/maker")
public class MakerController  {
    @Reference(timeout = 10000)
    private MakerService makerService;

    @Autowired
    JedisComponent jedisComponent;

    //获取最新服务产品
    @GetMapping("/getProductByArea")
    @ResponseBody
    public JSONUtils getProductByArea(String areaCode,Integer limit){
        return makerService.getProductByArea(areaCode,limit);
    }

    //获取轮播(预警+宣传+产品)
    @GetMapping("/getIndexSlideInfo")
    @ResponseBody
    public JSONUtils getIndexSlideInfo(String areaCode,Integer limit){
        return makerService.getIndexSlideInfo(areaCode,limit);
    }

    //获取首页宣传广告
    @GetMapping("/getSlidesShow")
    @ResponseBody
    public JSONUtils getSlideSshow(String areaCode,Integer limit){
        return makerService.getSlidesShow(areaCode,limit);
    }

    //获取广告
    @GetMapping("/getAdSlideInfo")
    @ResponseBody
    public JSONUtils getAdSlideInfo(String areaCode,Integer state,Integer isuse,Integer limit){
        return makerService.getAdSlideInfo(areaCode,state,isuse,limit);
    }

    // 获取溯源列表类型
    @GetMapping("/getTraceTypeList")
    @ResponseBody
    public JSONUtils getTraceTypeList(String areaCode,String userId,String farm){
        String key="/cloud/maker/getTraceTypeList"+areaCode+userId+farm;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=makerService.getTraceTypeList(areaCode,userId,farm);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存半个小时
        jedisComponent.setKeyTime(key,3600*3);
        //设置时效 保存半个小时
        return jsonUtils;
    }

    // 获取好产品列表
    @GetMapping("/getTraceList")
    @ResponseBody
    public JSONUtils getTraceList(String areaCode,String userId,String farm,String subject){
        String key="/cloud/maker/getTraceList"+areaCode+userId+farm+subject;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=makerService.getTraceList(areaCode,userId,farm,subject);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存5分钟
        jedisComponent.setKeyTime(key,300);
        //设置时效 保存5分钟
        return jsonUtils;
    }

    // 好产品访问量、点赞数、分享数更新
    @PostMapping("/updateGoodsRead")
    @ResponseBody
    public Integer updateProductRead(String gtype,String gid,String genre){
        return  makerService.updateGoodsRead(gtype,gid,genre);
    }

    // 好产品访问量、点赞数、分享数统计
    @GetMapping("/getGoodsReadCount")
    @ResponseBody
    public JSONUtils getGoodsReadCount(String areaCode,String gtype,Integer limit){
        return  makerService.getGoodsReadCount(areaCode,gtype,limit);
    }

    // 获取美丽乡村类型列表
    @GetMapping("/getCountryTypeList")
    @ResponseBody
    public JSONUtils getCountryTypeList(String areaCode){
        String key="/cloud/maker/getCountryTypeList"+areaCode;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=makerService.getCountryTypeList(areaCode);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存1小时
        jedisComponent.setKeyTime(key,3600);
        //设置时效 保存1小时
        return jsonUtils;
    }

    // 获取美丽乡村列表
    @GetMapping("/getCountryList")
    @ResponseBody
    public JSONUtils getCountryList(String areaCode,String tcode){
        String key="/cloud/maker/getCountryList"+areaCode+tcode;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=makerService.getCountryList(areaCode,tcode);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存1分钟
        jedisComponent.setKeyTime(key,60);
        //设置时效 保存1分钟
        return jsonUtils;
    }

    // 美丽乡村访问量、点赞数、分享数更新
    @PostMapping("/updateCountryRead")
    @ResponseBody
    public Integer updateCoRead(String cid,String ctype){
        return  makerService.updateCountryRead(cid,ctype);
    }

    // 美丽乡村访问量、点赞数、分享数统计
    @GetMapping("/getCountryReadCount")
    @ResponseBody
    public JSONUtils getCountryReadCount(String areaCode,String Ctype,Integer limit){
        return  makerService.getCountryReadCount(areaCode,Ctype,limit);
    }

    //获取首页定制功能
    @GetMapping("/getOrderMenuByUserId")
    @ResponseBody
    public JSONUtils getOrderMenuByUserId(Integer userId){
        return    makerService.getOrderMenuByUserId(userId);
    }

    @GetMapping("/getExpertList")
    @ResponseBody
    public JSONUtils getExpertList(Integer userId,String expertName, Integer subjectId, String areaCode,Integer state, Integer page, Integer size){
        String key="/cloud/maker/getExpertList"+userId+expertName+subjectId+areaCode+state+page+size;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=makerService.getExpertList(userId,expertName,subjectId,areaCode,state,page,size);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存半个小时
        jedisComponent.setKeyTime(key,3600);
        //设置时效 保存半个小时
        return jsonUtils;
    }

    //关注
    @PutMapping("/putExpertAttention")
    @ResponseBody
    public JSONUtils putExpertAttention(Integer userId,Integer expertId){
        return makerService.putExpertAttention(userId,expertId);
    }

    @DeleteMapping("/delExpertAttention")
    @ResponseBody
    public JSONUtils delExpertAttention(Integer userId,Integer expertId){
        return makerService.delExpertAttention(userId,expertId);
    }

    @PutMapping("/putAdSlideInfo")
    @ResponseBody
    public JSONUtils putAdSlideInfo(@RequestBody AdInfo adInfo){
        return  makerService.putAdSlideInfo(adInfo);
    }

    @PostMapping("/saveAdSlideInfo")
    @ResponseBody
    public JSONUtils saveAdSlideInfo(@RequestBody AdInfo adInfo){
        return  makerService.saveAdSlideInfo(adInfo);
    }

    @DeleteMapping("/delAdSlideInfo")
    @ResponseBody
    public JSONUtils delAdSlideInfo(Integer adInfoId){
        return  makerService.delAdSlideInfo(adInfoId);
    }

    @GetMapping("/putMenuClick")
    @ResponseBody
    public  JSONUtils putMenuClick(String menuCode,Integer userId,String areaCode){
        return  makerService.putMenuClick(menuCode,userId,areaCode);
    }
    @GetMapping("/getUserList")
    @ResponseBody
    public JSONUtils getUserList(String roleCode,String userName, String areaCode, Integer page, Integer size){
        return  makerService.getUserList(roleCode,userName,areaCode,page,size);
    }

    //产品组列表
    @GetMapping("/getProductGroupList")
    @ResponseBody
    public JSONUtils getProductGroupList(String areaCode,Integer templateId){
        String key="/cloud/maker/getProductGroupList"+areaCode+templateId;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=makerService.getProductGroupList(areaCode,templateId);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存半个小时
        jedisComponent.setKeyTime(key,3600);
        //设置时效 保存半个小时
        return jsonUtils;
    }

    //产品列表
    @GetMapping("/getWarningList")
    @ResponseBody
    public JSONUtils getWarningList(String areaCode,String cdate){
        return  makerService.getWarningList(areaCode,cdate);
    }

    //产品列表
    @GetMapping("/getProductList")
    @ResponseBody
    public JSONUtils getProductList(String groupIds){
        String key="/cloud/maker/getProductList"+groupIds;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=makerService.getProductList(groupIds);;
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存3分钟
        jedisComponent.setKeyTime(key,180);
        return jsonUtils;
    }

    //内外网用户登录
    @GetMapping("/login")
    @ResponseBody
    public JSONUtils login(String loginName,String pwd){return  makerService.login(loginName,pwd);}

    // 获取游客模式下菜单
    @GetMapping("/getVisitorMenuList")
    @ResponseBody
    public JSONUtils getVisitorMenuList(String areaCode){
        return    makerService.getVisitorMenuList(areaCode);
    }

    // 公众服务产品(阅读、点赞、分享)数统计
    @GetMapping("/getPublicProductCount")
    @ResponseBody
    public JSONUtils getPublicProductCount(String areaCode,String Ctype,Integer limit){
        return    makerService.getPublicProductCount(areaCode,Ctype,limit);
    }

}
